<?php

/*
 * Niken Larasati
 * larasati.n@students.amikom.ac.id
 */

class status_kawin extends CI_Controller {

    public function __construct() {
        parent::__construct();
    }

    function form_status_kawin() {
        $this->template->load('halaman_v', 'admin/status_kawin/tambah_status_kawin_v');
    }

    function tambah() {
        if ($this->input->post('tambah') != NULL) {
            $data['idstatus_kawin'] = $this->input->post('idstatus_kawin');
            $data['status_kawin'] = $this->input->post('status_kawin');

            $this->load->model('umum_m');
            $this->umum_m->tambah('status_kawin', $data);
            $this->tampil();
        }
    }

    function ubah($id = NULL) {
        if ($id != NULL) {
            $this->load->model('umum_m');
            $data['data_status_kawin'] = $this->umum_m->ambil_data('status_kawin', 'idstatus_kawin = ' . $id)->row();
            $this->template->load('halaman_v', 'admin/status_kawin/ubah_status_kawin_v', $data);
        } else {
            redirect('admin/status_kawin');
        }
    }

    function simpan_ubah() { //kalau data tidak diubah,maka....?
        if ($this->input->post() != null) {
            $status_kawin['idstatus_kawin'] = $this->input->post('idstatus_kawin');
            $status_kawin['status_kawin'] = $this->input->post('status_kawin');

            $this->load->model('umum_m');
            if ($this->umum_m->ubah('status_kawin', $status_kawin, 'idstatus_kawin', $status_kawin['idstatus_kawin'])) {
                redirect('admin/status_kawin/tampil');
            }
        }
    }

    function tampil() {
        $this->load->model('status_kawin_m');
        $data['status_kawin'] = $this->status_kawin_m->ambil_data();
        $this->template->load('halaman_v', 'admin/status_kawin/tampil_status_kawin_v', $data);
    }
    
    function hapus($id = NULL) {
        if ($id != NULL) {
            $this->load->model('umum_m');
            $status = $this->umum_m->cek_relasi_tabel('penduduk', 'idstatus_kawin', $id);
            if ($status == 0) {
                $this->umum_m->hapus_data_tabel('status_kawin', array('idstatus_kawin' => $id));
                $this->tampil();
            }
        }
    }

}

?>